package com.tl.khadmin.service.impl;
  
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service; 

import com.tl.khadmin.bean.ProductAttribute; 
import com.tl.khadmin.mapper.ProductAttributeMapper;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.ProductAttributeIService;
import com.tl.khadmin.util.CommonUtil; 

@Service
public class ProductAttributeServiceImpl implements ProductAttributeIService{
	
	@Resource
	private ProductAttributeMapper productAttributeMapper;
	
	public List<ProductAttribute> listProductAttribute(Map<String, Object> param){
		return productAttributeMapper.listProductAttribute(param); 
	}
	
	@Override
	public String updateProductAttribute(ProductAttribute productAttribute) { 
		int result = productAttributeMapper.updateByPrimaryKeySelective(productAttribute);
		return CommonUtil.returnMapResultByRows(result, "修改成功", "修改失败，请重试");
	}
	
	@Override
	public Page<ProductAttribute> showProductAttributeByPage(Integer pageNum, Integer pageSize, Map<String, Object> params) {
		Page<ProductAttribute> page=new Page<ProductAttribute>(pageNum, pageSize);
        params.put("page", page);   
        List<ProductAttribute> list= productAttributeMapper.showProductAttributeByPage(params);  
		page.setResult(list);
		return page;
	}

	@Override
	public String saveProductAttribute(HttpSession session, ProductAttribute productAttribute) {  
		int result = productAttributeMapper.insertSelective(productAttribute);
		return CommonUtil.returnMapResultByRows(result, "添加成功", "添加失败，请重试");
	}

	@Override
	public String deleteByIds(String ids) {
		String[] idsArr = ids.substring(0,ids.length()-1).split(",");
		try{
			int result = productAttributeMapper.deleteByIds(idsArr);
		}catch(Exception ex) {
			return CommonUtil.returnMapResultByRows(0, "删除成功","删除失败，请重试");
		} 
		return CommonUtil.returnMapResultByRows(1, "删除成功","删除失败，请重试");
	}

	@Override
	public Map<String, Object> queryProductAttributeById(Long id) {
		Map<String, Object> result = new HashMap<>();
		ProductAttribute productAttribute = productAttributeMapper.selectByPrimaryKey(id); 
		result.put("productAttribute", productAttribute); 
		return result;
	}

}
